65ae4b
@@ -25,53 +25,60 @@
import com.gemstone.gemfire.cache.util.ObjectSizer;
 
 /**
  * Simple utility class used for defining nested factory-method like definitions w/o polluting the container with useless beans.
- * 
+ * <p/>
  * @author Costin Leau
+ * @author John Blum
+ * @see org.springframework.beans.factory.FactoryBean
+ * @see org.springframework.beans.factory.InitializingBean
+ * @see com.gemstone.gemfire.cache.EvictionAttributes
+ * @see com.gemstone.gemfire.cache.util.ObjectSizer
  */
+@SuppressWarnings("unused")
 class EvictionAttributesFactoryBean implements FactoryBean<EvictionAttributes>, InitializingBean {
 
-	private EvictionAttributes evictionAttr;
+	private EvictionAction action = null;
+
+	private EvictionAttributes evictionAttributes;
+
+	private EvictionType type = EvictionType.ENTRY_COUNT;
 
 	private Integer threshold = null;
+
 	private ObjectSizer objectSizer = null;
-	private EvictionAction action = null;
-	private EvictionType type = EvictionType.ENTRY_COUNT;
 
 	public void afterPropertiesSet() {
-		if (action == null) {
-			action = EvictionAction.DEFAULT_EVICTION_ACTION;
-		}
-
-		evictionAttr = createAttributes();
+		this.action = (this.action != null ? action : EvictionAction.DEFAULT_EVICTION_ACTION);
+		evictionAttributes = createAttributes();
 	}
 
-	private EvictionAttributes createAttributes() {
+	EvictionAttributes createAttributes() {
 		switch (type) {
-		case HEAP_PERCENTAGE:
-			return EvictionAttributes.createLRUHeapAttributes(objectSizer, action);
-
-		case MEMORY_SIZE:
-			if (threshold != null) {
-				return EvictionAttributes.createLRUMemoryAttributes(threshold, objectSizer, action);
-			}
-			return EvictionAttributes.createLRUMemoryAttributes(objectSizer, action);
-
-		// consider entry count as default
-		case ENTRY_COUNT:
-		default:
-			if (threshold != null) {
-				return EvictionAttributes.createLRUEntryAttributes(threshold, action);
-			}
-			return EvictionAttributes.createLRUEntryAttributes();
+			case HEAP_PERCENTAGE:
+				if (threshold != null) {
+					throw new IllegalArgumentException(
+						"The HEAP_PERCENTAGE (LRU_HEAP algorithm) does not support threshold (a.k.a. maximum)!");
+				}
+				return EvictionAttributes.createLRUHeapAttributes(objectSizer, action);
+			case MEMORY_SIZE:
+				if (threshold != null) {
+					return EvictionAttributes.createLRUMemoryAttributes(threshold, objectSizer, action);
+				}
+				return EvictionAttributes.createLRUMemoryAttributes(objectSizer, action);
+			case ENTRY_COUNT:
+			default:
+				if (threshold != null) {
+					return EvictionAttributes.createLRUEntryAttributes(threshold, action);
+				}
+				return EvictionAttributes.createLRUEntryAttributes();
 		}
 	}
 
 	public EvictionAttributes getObject() {
-		return evictionAttr;
+		return evictionAttributes;
 	}
 
 	public Class<?> getObjectType() {
-		return (evictionAttr != null ? evictionAttr.getClass() : EvictionAttributes.class);
+		return (evictionAttributes != null ? evictionAttributes.getClass() : EvictionAttributes.class);
 	}
 
 	public boolean isSingleton() {
@@ -79,17 +86,17 @@
class EvictionAttributesFactoryBean implements FactoryBean<EvictionAttributes>,
 	}
 
 	/**
-	 * @return the threshold
+	 * @return the action
 	 */
-	public Integer getThreshold() {
-		return threshold;
+	public EvictionAction getAction() {
+		return action;
 	}
 
 	/**
-	 * @param threshold the threshold to set
+	 * @param action the action to set
 	 */
-	public void setThreshold(Integer threshold) {
-		this.threshold = threshold;
+	public void setAction(EvictionAction action) {
+		this.action = action;
 	}
 
 	/**
@@ -107,17 +114,17 @@
class EvictionAttributesFactoryBean implements FactoryBean<EvictionAttributes>,
 	}
 
 	/**
-	 * @return the action
+	 * @return the threshold
 	 */
-	public EvictionAction getAction() {
-		return action;
+	public Integer getThreshold() {
+		return threshold;
 	}
 
 	/**
-	 * @param action the action to set
+	 * @param threshold the threshold to set
 	 */
-	public void setAction(EvictionAction action) {
-		this.action = action;
+	public void setThreshold(Integer threshold) {
+		this.threshold = threshold;
 	}
 
 	/**
@@ -133,4 +140,5 @@
class EvictionAttributesFactoryBean implements FactoryBean<EvictionAttributes>,
 	public void setType(EvictionType type) {
 		this.type = type;
 	}
-}
\ No newline at end of file
+
+}
